/* Echo
   (c)2002 Trilinear
*/

#include "echo.h"

#ifndef WIN32
KOS_INIT_ROMDISK(romdisk);

pvr_init_params_t params = {
        // Enable opaque polygons with size 16 
        { PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_0 },

        // Vertex buffer size 512K 
        512*1024
};
#endif

int levelcompleted[10];
int levelscores[10];
float OWangle;
char OWdir;
char OWunlock;
GLuint texletters;
cont_cond_t cond;
uint8	c;

void resetsystem() {
	int i;

	OWangle=0;
	OWdir=2;
	for (i=0;i<10;i++) {
		levelcompleted[i]=2;//not viable 
		levelscores[i]=0;
	}
	levelcompleted[0]=1;
	levelcompleted[1]=0;
	levelcompleted[3]=0;
	levelcompleted[5]=0;			
}

void initsystem() {
	// Initialize KOS 
#ifndef WIN32
	pvr_init(&params);
	glKosInit();
#endif
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(33.0f, 640.0f / 480.0f, 4.0f, 10000.0f);
//	gluPerspective(33.0f, 640.0f / 480.0f, 4.0f, 10000.0f);
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_CULL_FACE);
//	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);

	glEnable(GL_DEPTH_TEST);
	glClearColor(0,0,0,1);

	loadpng("rd\\font.txa",PNG_FULL_ALPHA ,&texletters);
//	loadjpg("rd\\echotile.jpg", 256, &tex_tile[0]);

	resetsystem();
}

void killsystem() {
	glDeleteTextures(1, &texletters);
}



#ifdef WIN32
int GameLoop() {
#else
int main() {
#endif

	int retval=1;
	int lives=4;
	int level=0;
	int score=0;
	initsystem();
//	if (rungame(0,1,0,&lives,&score)==3) return 0;//title
	if (rungame(level,1,0,&lives,&score)==3) return 0;//title

	//	retval=rungame(level,0,1,&lives,&score);
//	if (retval==3) return 0;

	score=0;
	while (1) {
		retval=runoverworld(&level,&lives,&score);
		if (retval==3) break;//title

		retval=rungame(level,0,1,&lives,&score);
		if (retval==3) break;
		if (retval==2) levelcompleted[level]=1;
		if (lives<1) {
			lives=4;
			level=0;
			score=0;
			resetsystem();
		}else{
			if (score>levelscores[level]) levelscores[level]=score;
		}
		score=0;
	}
	killsystem();
	
	return 0;
}


